//
//  UIButtonExtension.swift
//  LPSina
//
//  Created by apple on 16/3/23.
//  Copyright © 2016年 apple. All rights reserved.
//

import UIKit

extension UIButton {
    
    //便利构造函数
    convenience init(imageName: String , bgImageName: String) {
    
        self.init()//遍历构造函数里面必须调用这个，不然会报错
        
        //按钮的图片
        setImage(UIImage(named: imageName), forState: .Normal)
        setImage(UIImage(named: imageName + "_highlighted"), forState: .Highlighted)
        
        //按钮的图片按钮的背景图片
        setBackgroundImage(UIImage(named: bgImageName), forState: .Normal)
        setBackgroundImage(UIImage(named: bgImageName + "_highlighted"), forState: .Highlighted)
        
        //设置尺寸
        sizeToFit()
    }
    
    convenience init(imageName: String , target: AnyObject , action: Selector) {
        
        self.init()
        
        setImage(UIImage(named: imageName), forState: .Normal)
        setImage(UIImage(named: imageName + "_highlighted"), forState: .Highlighted)
        addTarget(target, action: action , forControlEvents: .TouchUpInside)
        sizeToFit()
    }
}